package com.seal.commons.monitor;

import com.seal.commons.jms.MessageSender;
import com.seal.commons.monitor.dto.ServiceMonitorDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;


@Component
public class ServiceMonitorListener implements ApplicationListener<ServiceMonitorEvent> {

    @Autowired
    private MessageSender messageSender;

    @Value("${monitor.business.send.message}")
    private String monitorTopic;


    @Override
    public void onApplicationEvent(ServiceMonitorEvent event) {
        ServiceMonitorDTO serviceMonitorDTO = (ServiceMonitorDTO) event.getSource();
        messageSender.send(monitorTopic, "", serviceMonitorDTO);
    }
}
